package com.framework.base.util;

import java.util.HashMap;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;

public class OperationPaserUtil {
/**
 * 
 * @Description:功能描述
 * @author：刘明云
 * @Date 2011-6-20 上午11:34:29
 */
    @SuppressWarnings("unchecked")
	public boolean parseRight(String operation, ServletContext context,
                              HttpSession session) throws JspException {
        try {
            if (operation == null || "".equals(operation)) {
                return true;
            }
            int index = operation.indexOf(".");
            if (index == -1) {
                return false;
            }
            String module = operation.substring(0, index);
            String action = operation.substring(index + 1, operation.length());
            if (module == null || action == null) {
                return false;
            }
            HashMap<String,String> allRight = (HashMap<String,String>) session.getAttribute("userPermissions");
            String currentModuleAllRight = (String) (allRight.get(module));
            if (currentModuleAllRight != null &&currentModuleAllRight.length()>0){
            	String operations[] = currentModuleAllRight.split(",");
            	for (String oper : operations) {
					if(oper.equals(action)){
						return true;
					}
				}
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return false;
    }
}
